<?php

class User extends Controller {

    function __construct() {
        parent::Controller();

                $this->load->library('session');
        $this->load->model('Auth');
        $ckeck = $this->Auth->login($this->session->userdata('login'));


        if ($this->session->userdata('hash') != '' && $ckeck->Hash === $this->session->userdata('hash'))
           return;

        if ($this->uri->segment(2) === 'login')
            return;

        redirect('autorize/login');

    }

    function name() {
        
        $data['url'] = base_url();
//
        $this->load->model('Users_model', 'Users');
        $this->load->model('Tools_model', 'Tools');
        //
        $data['user'] = $this->Users->showUser($this->uri->segment(3));
        //$data['user']->LastConnect = date($this->Tools->dateReplace(0, date("N", $data['user']->LastActivityTime)) . ", " . $this->Tools->dateReplace(date("m", $data['user']->LastActivityTime), 0) . "  d, Yрік, о H:i:s", $data['user']->LastActivityTime);
        $data['streets'] = $this->Users->showStreets();
        $data['tariffs'] = $this->Users->showTariffs();
        $data['statuses'] = $this->Users->getStatuses();
        $data['tasks'] = $this->Users->getTasksUser($this->uri->segment(3));
        $this->load->view('header', $data);
        $this->load->view('menu', $data);
        $this->load->view('user', $data);
        $this->load->view('footer', $data);

        if ($_POST['save']) {
            //print_r($_POST['options']);
            $this->Users->userEdit($this->uri->segment(3));
            redirect($data['url'] . "user/name/" . $data['user']->login, 'refresh');
        }
    }




}

